﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Gola.VN.Scb.Web.Presentation.Helpers
{
    public class Utilities
    {
        private const string ViewFormat = "{0}/{1}/{2}";
        private const string ViewSearchFormat = "{0}/{1}/{2}?keyword={2}";
        private const string ProductsViewFormat = "{0}/{1}?keyword={2}";

        private const string ProductView = "/Product";
        private const string CategoryView = "/Category";
        private const string ProductDetailAction = "Productdetail";
        private const string CategoryDetailAction = "Display";
        private const string ProductProductsAction = "Products";

        public static string GetProductDetailView(int id, string keyword = "")
        {
            return string.IsNullOrEmpty(keyword) ? string.Format(ViewFormat, ProductView, ProductDetailAction, id) :
                string.Format(ViewSearchFormat, ProductView, ProductDetailAction, id, keyword);
        }

        public static string GetCategoryDetailView(int id, string keyword = "")
        {
            return string.IsNullOrEmpty(keyword) ? string.Format(ViewFormat, CategoryView, CategoryDetailAction, id) :
                string.Format(ViewSearchFormat, CategoryView, CategoryDetailAction, id, keyword);
        }

        public static string GetProductsView(string title)
        {
            return string.Format(ProductsViewFormat, ProductView, ProductProductsAction, title);
        }

        public static int PageCount
        {
            get
            {
                return 6;
            }
        }

        public static int FindStartIndex(int pageIndex, int itemCount)
        {
            int start = 0;
            int pageSize = PageCount;

            start = itemCount > pageIndex * pageSize ? pageIndex * pageSize : itemCount - pageSize;

            return System.Math.Max(0, start);
        }

        public static List<T> GetPageView<T>(int pageIndex, List<T> items) where T : class
        {
            int start = FindStartIndex(pageIndex, items.Count);

            return items.GetRange(start, System.Math.Min(items.Count - start, PageCount));
        }

        public static string GetTitle(string title)
        {
            return string.Format("Gola.vn - {0}, so sánh giá, thông báo giảm giá, tivi, máy tính xách tay, điện thoại di động, mobile, laptop, điều hòa, dieu hoa,", title);
        }

        
    }
}